package res

type errCode struct {
	Code int
	Msg  string
}

const ( // 分片上传成功

	SUCCESS                   = "SUCCESS"                   // 成功
	INSTANT_TRANSMISSION      = "INSTANT_TRANSMISSION"      //秒传
	UPLOAD_COMPLETE           = "UPLOAD_COMPLETE"           //上传完成
	PARAM_ERR                 = "PARAM_ERR"                 // 参数校验失败
	SYS_ERR                   = "SYS_ERR"                   // 系统错误
	INVALID_TOKEN             = "INVALID_TOKEN"             //无效的凭证或令牌
	EXPIRED_TOKEN             = "EXPIRED_TOKEN"             //过期的凭证或令牌
	TOKEN_EXPIRED_MAX_REFRESH = "ErrTokenExpiredMaxRefresh" // 令牌过期，超过最大可刷新时间
	ACCOUNT_OR_PWD_ERR        = "ACCOUNT_OR_PWD_ERR"        //账号或密码有误
	LOGIN_EXPIRED             = "LOGIN_EXPIRED"             //登录过期
	USER_EXIST                = "USER_EXIST"                // 用户已存在
	USER_NOT_EXIST            = "USER_NOT_EXIST"            // 用户不存在
	ORIGINAL_PWD_ERR          = "ORIGINAL_PWD_ERR"          //原始密码错误
	ORIGINAL_PWD_SAME_NEW_PWD = "ORIGINAL_PWD_SAME_NEW_PWD" //原始密码不能和新密码相同
	//文件模块错误
	LACK_OF_SPACE                  = "LACK_OF_SPACE"                  //空间不足
	UPLOAD_FAIL                    = "UPLOAD_FAIL"                    //上传失败
	UPLOAD_ID_INVALID              = "UPLOAD_ID_INVALID"              //上传ID无效
	FOLDER_NOT_EXIST               = "FOLDER_NOT_EXIST"               //文件夹不存在
	SAME_FOLDER_NAME_EXISTS        = "SAME_FOLDER_NAME_EXISTS"        // 此目录下已存在同名文件夹，请更换文件夹名称再试
	FILE_CANT_MOVE_TO_ORIGINAL_DIR = "FILE_CANT_MOVE_TO_ORIGINAL_DIR" //不能移动到原目录中
	CREATE_FOLDER_FAIL             = "CREATE_FOLDER_FAIL"             // 创建文件夹失败
	SAME_FILE_EXISTS               = "SAME_FILE_EXISTS"               //此目录下已存在同名文件，请更换名称再试
	//外部分享模块错误
	SHARE_NOT_EXIST_OR_EXPIRED = "SHARE_NOT_EXIST_OR_EXPIRED" //分享不存在或已失效
	TI_MA_CUO                  = "TI_MA_CUO"                  //提取码错误
	SHARE_EXPIRED_REVERIFY     = "SHARE_EXPIRED_REVERIFY"     //分享验证失效！请重新验证
)

var errCodeMap = map[string]errCode{
	"PARAM_ERR":                      {10001, "参数校验失败"},
	"SYS_ERR":                        {10002, "系统错误"},
	"INVALID_TOKEN":                  {10003, "无效的凭证或令牌"},
	"EXPIRED_TOKEN":                  {10004, "过期的凭证或令牌"},
	"TOKEN_EXPIRED_MAX_REFRESH":      {10005, "令牌过期，超过最大可刷新时间"},
	"LOGIN_EXPIRED":                  {10006, "登录过期"},
	"ACCOUNT_OR_PWD_ERR":             {40001, "账号或密码有误"},
	"USER_EXIST":                     {40002, "用户已存在"},
	"USER_NOT_EXIST":                 {40003, "用户不存在"},
	"ORIGINAL_PWD_SAME_NEW_PWD":      {40004, "原始密码不能和新密码相同"},
	"ORIGINAL_PWD_ERR":               {40005, "原始密码错误"},
	"LACK_OF_SPACE":                  {50001, "空间不足"},
	"UPLOAD_FAIL":                    {50002, "上传失败"},
	"UPLOAD_ID_INVALID":              {50003, "上传ID无效"},
	"FOLDER_NOT_EXIST":               {50004, "文件夹不存在"},
	"SAME_FOLDER_NAME_EXISTS":        {50005, "此目录下已存在同名文件夹，请更换文件夹名称再试"},
	"SAME_FILE_EXISTS":               {50006, "此目录下已存在同名文件，请更换文件名称再试"},
	"CREATE_FOLDER_FAIL":             {50007, "创建文件夹失败"},
	"FILE_CANT_MOVE_TO_ORIGINAL_DIR": {50008, "不能移动到原目录中"},
	"SHARE_NOT_EXIST_OR_EXPIRED":     {70001, "分享不存在或已失效"},
	"TI_MA_CUO":                      {70002, "提取码错误"},
	"SHARE_EXPIRED_REVERIFY":         {70003, "分享验证失效！请重新验证"},
}
var resultCodeMap = map[string]errCode{
	"SUCCESS":              {200, "成功"},
	"INSTANT_TRANSMISSION": {201, "秒传"},
	"UPLOAD_COMPLETE":      {203, "上传完成"},
}

func getCode(ErrType string) errCode {
	if _, ok := errCodeMap[ErrType]; ok {
		return errCodeMap[ErrType]
	}
	if _, ok := resultCodeMap[ErrType]; ok {
		return resultCodeMap[ErrType]
	}
	return errCode{10000, "未知错误"}
}
